function subArr(arr = []) {
    let result = []
    if (arr.length == 1) {
        if (arr[0].active) {
            result.push(arr[0]);
        }
    }

    let flag = 0;//
    for (let i = 0; i < arr.length; i++) {
        if (arr[i].active) {
            flag++;
        } else {
            if (flag > 1) {
                //flag 大于1表示 有超过连续的两个真值； 把头尾添加到数组种               
                result.push(arr[i - flag]);
                result.push(arr[i - 1]);
            }
            if (flag == 1) {
                if (!arr[i - 2].active) {
                    result.push(arr[i - 1]);
                    result.push(arr[i - 1]);
                }
            }
            flag = 0;
        }
    }
    return result;
}

let arr = [
    { active: true, index: 0 },
    { active: true, index: 1 },
    { active: true, index: 2 },
    { active: false, index: 3 },
    { active: true, index: 4 },
    { active: false , index: 5 },
    { active: true, index: 6 },
    { active: true, index: 7 },
    { active: false, index: 8 },
    { active: false, index: 9 },
]
console.log(subArr(arr));